<?php

namespace App\Remote\Mybank;

use App\Exceptions\BaseException;
use App\Kuafu\Mybank\Enum\MybankFunctionEnum;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Http\Request;

class MybankRegisterRemote extends Remote
{
    /**
     * 预入驻
     *
     * @param array $params
     * @return mixed
     * @throws GuzzleException
     */
    public static function preRegister(array $params)
    {
        return self::customRequestV2(
            config('pay.mybank.bkServerUrl'),
            Request::METHOD_POST,
            self::buildXmlRequestData($params, MybankFunctionEnum::BKMERCHANTPROD_MERCH_APPLET_PRE_REGISTER)
        );
    }

    public static function arrangementAudit(string $arrangementNo, string $merchantId, string $auditResult)
    {
        return self::customRequestV2(
            config('pay.mybank.bkServerUrl'),
            Request::METHOD_POST,
            self::buildXmlRequestData([
                "IsvOrgId"      => Remote::getIsvOrgId(),
                "MerchantId"    => $merchantId,
                "AuditResult"   => $auditResult,
                "ArrangementNo" => $arrangementNo
            ], MybankFunctionEnum::MERCHANTPROD_MERCHANT_ARRANGEMENT_AUDIT)
        );
    }

    /**
     * @param string $merchantId
     * @return mixed
     * @throws GuzzleException
     * @throws BaseException
     */
    public static function arrangementQuery(string $merchantId)
    {
        return self::customRequestV2(
            config('pay.mybank.bkServerUrl'),
            Request::METHOD_POST,
            self::buildXmlRequestData([
                "IsvOrgId"        => Remote::getIsvOrgId(),
                "MerchantId"      => $merchantId,
                "ArrangementType" => "SUB_ACCOUNT_WITHHOLD"
            ], MybankFunctionEnum::MERCHANTPROD_MERCHANT_ARRANGEMENT_INFO_QUERY)
        );
    }
}
